package com.gt.web.srv.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.gt.web.api.common.R;
import com.gt.web.srv.domain.ActivityGroup;
import com.gt.web.srv.domain.RepairApplication;
import com.gt.web.srv.domain.SsParticipants;
import com.gt.web.srv.mapper.ActivityGroupMapper;
import com.gt.web.srv.mapstructs.ActivityGroupStruct;
import com.gt.web.srv.mapstructs.RepairApplicationStruct;
import com.gt.web.srv.mapstructs.SsParticipantsStruct;
import com.gt.web.srv.service.ActivityGroupService;
import com.gt.web.srv.web.api.command.ActivityGroupCommand;
import com.gt.web.srv.web.api.resource.ss.ActivityGroupResource;
import com.gt.web.srv.web.api.resource.ss.RepairApplicationResource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>describe</p >
 *
 * @author shenhuiyang
 * @version 1.0
 * @date 2025/5/29 18:52
 * @menu describe
 */
@Service
public class ActivityGroupServiceImpl implements ActivityGroupService {

    @Autowired
    private ActivityGroupMapper activityGroupMapper;

    @Override
    public ActivityGroupResource getById(Long ssParticipantsId) {
        return ActivityGroupStruct.INSTANCE.simple(activityGroupMapper.selectById(ssParticipantsId));
    }

    @Override
    public PageInfo<ActivityGroupResource> page(ActivityGroupCommand request) {
        PageHelper.startPage(request.getPageNum(), request.getPageSize());
        List<ActivityGroup> repairApplications = activityGroupMapper.selectList(ActivityGroupStruct.INSTANCE.simple(request));
        List<ActivityGroupResource> repairApplicationResources = ActivityGroupStruct.INSTANCE.simpleList(repairApplications);
        return new PageInfo<>(repairApplicationResources);
    }

    @Override
    public void save(ActivityGroupCommand dto) {
        ActivityGroup activityGroup = ActivityGroupStruct.INSTANCE.simple(dto);
        if (dto.getActivityGroupId() == null) {
            // 新增
            activityGroupMapper.insert(activityGroup);
        } else {
            // 更新
            activityGroupMapper.update(activityGroup);
        }
    }

    @Override
    public boolean updateStatus(Long activityGroupId, Integer status) {
        return activityGroupMapper.updateStatus(activityGroupId, status,null) > 0;
    }
}
